//
// File:    progform.h
// Brief:   测试程序编辑画面头文件
//
// History:
// ============================================================================
// 2010-11-01    Finux Chen <finuxchen@gmail.com>    创建
// 2010-12-16    Finux Chen <finuxchen@gmail.com>    使用Interview模式重构
// 2011-01-20    Finux Chen <finuxchen@gmail.com>    使用core模块新接口
// 2011-02-18    Finux Chen <finuxchen@gmail.com>
//               添加光量项目detail设定功能和item suffix相关处理
//
#ifndef _PROGFORM_H
#define _PROGFORM_H

#include <QMdiSubWindow>
#include <QString>
#include "../define.h"
#include "ui_programform.h"

QT_BEGIN_NAMESPACE
class QPushButton;
class QComboBox;
class QLabel;
class QTableWidget;
QT_END_NAMESPACE

struct EsdItemMap{
	QString itemNameSuffix;
	short	ch;
	short	index;
};

class ProgForm : public QMdiSubWindow
{
	Q_OBJECT

public:
	ProgForm(QWidget *parent = 0);
	~ProgForm();

	inline static int getChnCount() { return chnCount; }	
	void loadItems();

//signals:
//	void progPathChanged(const QString &path);

public slots:
	// 测试项目下拉框选项改变
	void itemKindSel(const QString& text);

	void itemAdd();
	void itemInsert();
	void itemDelete();

    //void devTypeChanged();
	void deviceTypeChanged(const QString& text);
	void detailSetting();
//	void openDevTypeDlg();

    //void saveProg2Shm();  // temp
	void clearItems();
	void createProg();
	void saveItems();

	void tableCellClicked(int r, int c);
	void formShouldReturn();

protected:
	void itemPosIns(int insPos);
	void handleDetailArray(int index, bool bForward);
    //void insItems2Prog(program_s *pprog);

private:
// FUNCTIONS /////////////////////////////////////////////////////
	QString checkNameSuffix(const QString& itemName);
	void updateEsdItemMap(int dccIndex);

//////////////////////////////////////////////////////////////////
/////// CONSTANTS	
	static const int PROG_TABLE_ROWS     = 11;
	static const int PROG_TABLE_MAX_COLS = 25;
	
	static const int kColWidth  = 150;
	static const int kRowHeight = 48;

//////////////////////////////////////////////////////////////////
/////// VARIANTS
	static int chnCount;	// Channel count
	det_u hueDetail[MAX_ITEM_QTY];
	EsdItemMap esdMap[MAX_ITEM_QTY];

	Ui_ProgramForm  ui;
	QComboBox       *deviceCombo;
	QComboBox		*comboItemSel;
	QPushButton		*btnDetail;
	QPushButton		*btnItemAdd;
	QPushButton		*btnItemIns;
	QPushButton		*btnItemDel;
	QPushButton		*btnItemClr;
	QPushButton		*btnProgNew;
	QPushButton		*btnProgSave;
	QPushButton		*backButton;
	QTableWidget	*table;
};

#endif
